import React from "react";
import {Card, message} from "antd";
import store from "./store";
import SearchForm from "../../components/index/SearchForm";
import {observer} from "mobx-react";
import ActionModal from "../../components/index/ActionModal";
import ActionDiv from "../../components/index/ActionDiv";
import ActionTable from "../../components/index/ActionTable";

@observer
class Test extends React.Component{
    constructor(props) {
        super(props);
        this.state = {
            reload:false
        }
    }

    componentDidMount() {
        let uri = this.getUri();
        if (uri){
            store.uri = uri;
            store.fetchRecords();
        }
    }

    getUri = (nextProps = null) => {
        let uri = nextProps ? nextProps.match.params.uri : this.props.match.params.uri;
        if (uri){
            return '/' + uri.replace(/\./g,"\/");
        }else {
            message.error("uri缺失")
            return false;
        }
    };

    //解决参数改变组件不更新的问题
    componentWillReceiveProps = (nextProps) => {
        let new_uri = this.getUri(nextProps);
        if (store.uri !== new_uri){
            store.uri = new_uri;
            store.fetchRecords()
        }
    };

    render() {
        return (
            <Card >
                {/*搜索表单*/}
                <SearchForm config={store.searchConfig}/>

                {/*表格外的操作*/}
                <ActionDiv config={store.actionDivConfig}/>

                {/*表格*/}
                <ActionTable />

                {/*弹窗*/}
                {
                    store.modalVisible && <ActionModal configUri={store.configUri} configParams={store.configParams}/>
                }
            </Card>
        )
    }
}

export default Test;
